package jeconbond.experiment.market.equilibrium;

import jeconbond.economic.resources.ResourceUtils;
import jeconbond.economic.systems.market.DefaultMarketRRSFactory;
import jeconbond.experiment.JEBExperimentFlow;
import jeconbond.experiment.generate.ProfitableNormFormGenerateDecorator;
import jeconbond.experiment.market.equilibrium.generate.MooreAgentsCreator;
import jeconbond.experiment.market.equilibrium.generate.MooreAutomataGenerator;
import jeconbond.experiment.market.equilibrium.generate.MooreEngineInitialiser;
import jeconbond.experiment.ui.reportage.EconomicContextER2CConverter;
import laboratoryQ.experiment.settings.ReflectionBasedSettingsContainer;
import laboratoryQ.experiment.ui.reportage.ExperimentReportage;
import laboratoryQ.flatness.Point;

public class MainMoonraker {
	public static void main(String[] args) {
		JEBExperimentFlow experimentFlow = new JEBExperimentFlow();

		MooreExperimentSettings settings = new MooreExperimentSettings();
		settings.initialise();

		settings.stepSize = 100;
		settings.stepCount = 80;
		settings.agentsCount = 100;
		settings.chainLength = 5;
		settings.produceProfit = 1.2;
		settings.agentGreedPercent = 2.7;
		settings.initResourceExceedPercent = 1.1;
		settings.initMoney = settings.chainLength * 5;
		settings.initMoney = 50.0;
		settings.observeCostsTraceLength = 10;
		settings.purchaseExceedPassivePeriod = settings.chainLength * 3;
		settings.concurrentPricePercent = 0.0;

		settings.utiliseExceedPeriod = -2.0;
		settings.purchaseExceedDayBudget = -2.0;
		settings.purchaseExceedPassivePeriod = -2;
		settings.purchaseExceedUseTrackLength = -2;

		settings.rrsFactory = new DefaultMarketRRSFactory();
		settings.resources = ResourceUtils.generateResources("r", 9);
		settings.experiment = experimentFlow;
		settings.randomSeed = 0.0;
		settings.zeroPoint = new Point(0.0, 0.0);
		settings.selectPropositionsPart = 1.0;
		settings.profitCostManagerFactory = MooreAutomataGenerator.MANAGER_FACTORY_INSTANCE;
		settings.validate();

		ReflectionBasedSettingsContainer settingsContainer =
			new ReflectionBasedSettingsContainer(settings);
		settingsContainer.sortFields(
				"stepSize", 
				"stepCount", 
				"agentsCount", 
				"chainLength", 
				"produceProfit", 
				"agentGreedPercent", 
				"initResourceExceedPercent", 
				"initMoney", 
				"observeCostsTraceLength", 
				"concurrentPricePercent", 
				"utiliseExceedPeriod", 
				"purchaseExceedDayBudget", 
				"purchaseExceedPassivePeriod", 
				"purchaseExceedUseTrackLength", 
				"randomSeed"
		);

		experimentFlow.automataGenerator = new ProfitableNormFormGenerateDecorator(new MooreAutomataGenerator());
		experimentFlow.agentCreator = new MooreAgentsCreator();
		experimentFlow.engineInitialiser = new MooreEngineInitialiser();

		ExperimentReportage experimentReportage =
			ExperimentReportage.newExperiment2componentReportage(
					settingsContainer,
					new EconomicContextER2CConverter("Moonracer experiment no concPr no util")
			);
		experimentReportage.showReportageFrame(args);
		
//		DiagramUtils.styleInsteadColor(moonrakerExpKit);
//		
//		javax.swing.JFileChooser fc = new javax.swing.JFileChooser();
//		fc.showSaveDialog(null);
//		java.io.File f = fc.getSelectedFile();
//		DiagramUtils.saveDiagrams(
//				moonrakerExpKit.getExperimentViewDrawers(),
//				experimentFlow,
//				f.getPath(), 
//				3500, 2000
//				);
	}
}
